package com.moss.common.domain;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.moss.common.entity.SysDeptEntity;
import com.moss.common.entity.SysGoodsCategoryEntity;
import com.moss.common.entity.SysMenuEntity;
import com.moss.common.entity.SysOrgEntity;
import lombok.Data;

import java.util.List;
import java.util.stream.Collectors;

@Data
public class TreeEntity {

    private static final long serialVersionUID = 1L;

    private Long id;

    private String label;

    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<TreeEntity> children;


    public TreeEntity(SysMenuEntity menu)
    {
        this.id = menu.getMenuId();
        this.label = menu.getMenuName();
        this.children = menu.getChildren().stream().map(TreeEntity::new).collect(Collectors.toList());
    }

    public TreeEntity(SysDeptEntity dept)
    {
        this.id = dept.getDeptId();
        this.label = dept.getDeptName();
        this.children = dept.getChildren().stream().map(TreeEntity::new).collect(Collectors.toList());
    }

    public TreeEntity(SysOrgEntity org) {
        this.id = org.getOrgId();
        this.label = org.getOrgName();
        this.children = org.getChildren().stream().map(TreeEntity::new).collect(Collectors.toList());
    }

    public TreeEntity(SysGoodsCategoryEntity goodsCategory) {
        this.id = goodsCategory.getId();
        this.label = goodsCategory.getCategoryName();
        this.children = goodsCategory.getChildren().stream().map(TreeEntity::new).collect(Collectors.toList());
    }
}
